
// createRouter 可执行函数,产出一个router路由实例对象 <=> 2.0的 new VueRouter
// createWebHashHistory 可执行函数,产出一个hash模式的路由配置对象
import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/Layout'
import Home from '@/views/Home'
import Play from '@/views/Playground'
// import Category from '@/views/Category'
import SubCategory from '@/views/Category/Sub'
// const SubCategory = () => import('@/views/Category/Sub')
// const SubCategory = function () {
//   return import('@/views/Category/Sub')
// }
import './permission'
import Cart from '@/views/Cart'

import GoodsDetail from '@/views/Goods'
import Login from '@/views/Login'
import Callback from '@/views/Login/Callback'
import Settlement from '@/components/Settlement'
import Pay from '@/views/Pay'
import PayCallback from '@/views/Pay/callback'

const routes = [
  {
    path: '/play',
    component: Play
  },
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/',
        component: Home
      },
      {
        path: '/category/:id', // params传参
        name: 'category',
        component: () => import('@/views/Category')
      },
      {
        path: '/subCategory/:id', // params传参
        name: 'subCategory',
        component: SubCategory
      },
      {
        path: '/goods/:id', // params传参
        // path: '/goods', // query传参
        component: GoodsDetail
      },
      {
        path: '/cart', // 购物车
        component: Cart
      },
      {
        path: '/settlement',
        component: Settlement
      },
      {
        path: '/pay',
        component: Pay
      }
    ]
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/login/callback',
    component: Callback
  },
  {
    path: '/pay/callback',
    component: PayCallback
  },
  //  /:pathMatch(.*)*   /:catchAll(./*)    /:pathMatch(.*)
  { path: '/:pathMatch(.*)*', redirect: '/' }
]

// createRouter 创建一个路由实例对象
const router = createRouter({
  // 使用hash方式实现路由
  history: createWebHashHistory(),
  // 配置路由规则，写法和之前一样
  routes
})

export default router
